import api from '../../api/index';
import { sdk } from '../../config/sdk';

Page({
  data: {
    loading: true
  },
  onLoad() {

  },
  onShow() {
    if (wx.getStorageSync('login')) {
      this.getUserInfo();
    }
  },
  
  // 获取用户信息
  async getUserInfo() {
    const { code, message, data } = await sdk.request({ url: api.getUserInfo, method: 'GET' });
    if (code != 1000) return this.$error(message);
    this.setData({
      userInfo: data,
      loading: false
    });
  },

  // 点击
  tapTo(e) {
    if (!wx.getStorageSync('login')) {
      return this.$showDialog({
        title: '系统提示',
        content: '你还未登录 请先登录',
        confirmText: '立即登录',
        success: res => {
          if (res.confirm) {
            this._toPath('pages/login/index')
          }
        }
      })
    };
    this._toPath(e.currentTarget.dataset.url)
  }
})